package com.turnengine.client.local.location.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Set Locations Enabled.
 */
public class SetLocationsEnabled implements ISetLocationsEnabled {

	/** The command id. */
	public static final short COMMAND_ID = 2006;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The enabled. */
	private boolean enabled;

	/**
	 * Creates a new Set Locations Enabled.
	 */
	public SetLocationsEnabled() {
	}

	/**
	 * Creates a new Set Locations Enabled.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param enabled the enabled
	 */
	public SetLocationsEnabled(long loginId, int instanceId, boolean enabled) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setEnabled(enabled);
	}

	/**
	 * Creates a new Set Locations Enabled.
	 * @param iSetLocationsEnabled the i set locations enabled
	 */
	public SetLocationsEnabled(ISetLocationsEnabled iSetLocationsEnabled) {
		setLoginId(iSetLocationsEnabled.getLoginId());
		setInstanceId(iSetLocationsEnabled.getInstanceId());
		setEnabled(iSetLocationsEnabled.getEnabled());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the enabled.
	 * @return the enabled.
	 */
	public boolean getEnabled() {
		return enabled;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the enabled.
	 * @param enabled the enabled to set.
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(751, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(enabled);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof SetLocationsEnabled) {
			SetLocationsEnabled compare = (SetLocationsEnabled) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.enabled, compare.enabled);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ISetLocationsEnabled compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.enabled, compare.getEnabled());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		string.append("enabled", enabled);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
